<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>主页</title>
    </head>
    <script type="text/javascript" src="../js/jquery-3.3.1.js"></script>
    <style>
	    body{	
	    	margin:0px;
	    	height:732px;
	    	width:1536px;
	    }
    	#navigator{
    		margin-top:1%;
			height:95%;
			width:10%;
			background-color:#3498DB;
			float:left;
		}
		#navigator a:link{
			color:white; 		
			text-decoration: none;
		}
		#navigator a:visited{
			color:white; 	 		
			text-decoration: none;
		}
		#navigator a:active{
			color:#CCCCCC;		
			text-decoration: none;
		}
		#content{
			margin-left:2%;
			margin-top:1%;
			height:97%;
			width:87%;
			float:left;
			overflow: hidden;
		}
		#content div{
			height:100%;
			width:100%;
			
			
		}
		#content #man{
			height:100%;
			width:100%;
			
		
		}
		#content #mis{
			height:100%;
			width:100%;
			
		
		}
		p{
			margin:0px;
		}
		ul li{
			margin-top:30%;
			color:white;
			font-weight:bolder;
			list-style: none;
		}
    </style>
     <body>
	     <div id="navigator">
	     	<ul>
	     		<li><a href="#area">安保区域</a><li>
	     		<li><a href="#man">安保人员</a><li>
	     		<li><a href="#mis">安保任务</a><li>
	     		<li><a href="#acc">重大事件</a><li>
	     	</ul>
	     </div>
	     <div  id="content">
	     	<div id="status">
	    	</div>
	     	<div id="area">
	     		<p>安保区域</p>
	     		<a href="/pmsystem/security/add_area.jsp">添加区域</a></br>
	     		<input type="text" id="areaCondition"><button id="areaSearch">搜索</button>
	     		<table border="1px" cellpadding="0px"  cellpadding="0px">
	     		</table>
	     		<p id="areap"><p>
	     	</div>
	     	<div id="man">
	     		<p>安保人员</p>
	     		<a href="/pmsystem/security/add_man.jsp">添加人员</a></br>
	     		<input type="text" id="manCondition"><button id="manSearch">搜索</button>
	     		<table border="1px" cellpadding="0px"  cellpadding="0px">
	     		</table>
	     		<p id="manp"><p>
	     	</div>
	     	<div id="mis">
	     		<p>安保任务</p>
	     		<a href="/pmsystem/security/add_mis.jsp">添加任务</a></br>
	     		开始日期<input type="date" id="misStartTime"><input type="date" id="misEndTime">
	     		截止日期<input type="text" id="misCondition"><button id="misSearch">搜索</button>
	     		<span id="progress"></span>
	     		<table border="1px" cellpadding="0px"  cellpadding="0px">
	     		</table>
	     		<p id="misp"><p>
	     	</div>
	     	<div id="acc">
	     		<p>重大事件</p>
	     		<a href="/pmsystem/security/add_accident.jsp">添加事件</a></br>
	     		日期<input type="date" id="accTime">
	     		<input type="text" id="accCondition"><button id="accSearch">搜索</button>
	     		<table border="1px" cellpadding="0px"  cellpadding="0px">
	     		</table>
	     		<p id="accp"><p>
	     	</div>
	     </div> 
	</body>
	<script type="text/javascript">
		$(function() {
			var pageSize = 5;
			//安保区域
			var areaCondition = $("#areaCondition").val();
			$("#areaSearch").click(function(){
				areaCondition = $("#areaCondition").val();
				showArea(1,areaCondition);
			})
			showArea(1,areaCondition);
			function showArea(pageNo,condition){
				var pageNum = 0 ;
				$("#area table").html("<tr><th>Id</th><th>名称</th><th>操作</th></tr>");
				$("#areap").html("");
				$.ajax({
					url:"findareapage",
					type:"get",
					contentType:'application/json',
					async:false,
					data:{'pageNo':pageNo,'pageSize':pageSize,'condition':condition},
					dataType:'json',
					success:function(data){
						pageNum = data.pageNum;
						$.each(data.areaPage,function(){
							var tr = document.createElement("tr");
							tr.innerHTML="<td>"+this.securityAreaId+"</td>"+
							 "<td>"+this.securityAreaName+"</td>"+
							 "<td><a href='/pmsystem/security/updatearea?id="+this.securityAreaId+"'>修改</a>/"+
				 			 "<a href='javascript:;' id='d"+this.securityAreaId+"'>删除</a></td>";
							$("#area table").append(tr);
				     		var id = this.securityAreaId;
				     		var deleteId = "#d"+id;
				     		$(deleteId).click(function(){
								$.ajax({
									url:'deletearea',
									method:'get',
									contentType:'application/json',
									dataType:'json',
									data:{'id':id},
									success:function(data){
										showArea(pageNo,condition);
									}
								});
							});
						});
						for(var i=1;i<=pageNum;i++){
							if(i==pageNo){
								var a = "<a href='#' class='"+i+"' style='font-size:20px'>"+i+"<a/>";
								$("#areap").append(a);
							}else{
								var a = "<a href='#' class='"+i+"'>"+i+"<a/>";
								$("#areap").append(a);
							}
						}
						for(var i=1;i<=pageNum;i++){
							var id = "#areap ."+i;
							$(id).click(function(){
								showArea($(this).attr("class"),areaCondition);
							});
						}
						if(data.areaPage.length==0)
							showArea(pageNo-1,condition && pageNum!=0);
					}
				})
			}
			//安保人员信息
			var manCondition = $("#manCondition").val();
			$("#manSearch").click(function(){
				manCondition = $("#manCondition").val();
				showMan(1,manCondition);
			})
			showMan(1,manCondition);
			function showMan(pageNo,condition){
				var pageNum = 0 ;
				$("#man table").html("<tr><th>Id</th><th>名称</th><th>联系方式</th><th>操作</th></tr>");
				$("#manp").html("");
				$.ajax({
					url:"findmanpage",
					type:"get",
					contentType:'application/json',
					async:false,
					data:{'pageNo':pageNo,'pageSize':pageSize,'condition':condition},
					dataType:'json',
					success:function(data){
						pageNum = data.pageNum;
						$.each(data.manPage,function(){
							var tr = document.createElement("tr");
							tr.innerHTML="<td>"+this.securityManId+"</td>"+
										 "<td>"+this.securityManName+"</td>"+
										 "<td>"+this.telephone+"</td>"+
										 "<td><a href='/pmsystem/security/updateman?id="+this.securityManId+"'>修改</a>/"+
	     					 			 "<a href='javascript:;' id='d"+this.securityManId+"'>删除</a></td>";
							$("#man table").append(tr);
				     		var id = this.securityManId;
				     		var deleteId = "#d"+id;
				     		$(deleteId).click(function(){
								$.ajax({
									url:'deleteman',
									method:'get',
									contentType:'application/json',
									dataType:'json',
									data:{'id':id},
									success:function(data){
										showMan(pageNo,condition);
									}
								});
							});
						});
						for(var i=1;i<=pageNum;i++){
							if(i==pageNo){
								var a = "<a href='#' class='"+i+"' style='font-size:20px'>"+i+"<a/>";
								$("#manp").append(a);
							}else{
								var a = "<a href='#' class='"+i+"'>"+i+"<a/>";
								$("#manp").append(a);
							}
						}
						for(var i=1;i<=pageNum;i++){
							var id = "#manp ."+i;
							$(id).click(function(){
								showMan($(this).attr("class"),manCondition);
							});
						}
						if(data.manPage.length==0 && pageNum!=0)
							showMan(pageNo-1,condition);
					}
				})
			}
			//安保任务信息
			var misCondition = $("#misCondition").val();
			var misStartTime = $("#misStartTime").val();
			var misEndTime = $("#misEndTime").val();
			$("#misSearch").click(function(){
				misCondition = $("#misCondition").val();
				misStartTime = $("#misStartTime").val();
				misEndTime = $("#misEndTime").val();
				showMis(1,misCondition,misStartTime,misEndTime);
			})
			showMis(1,misCondition);
			showProgress();
			function showMis(pageNo,condition,startTime,endTime){
				var pageNum = 0 ;
				$("#mis table").html("<tr><th>任务ID</th><th>区域ID</th><th>人员ID</th><th>日期</th><th>是否完成</th><th>备注</th><th>操作</th></tr>");
				$("#misp").html("");
				$.ajax({
					url:"findmispage",
					type:"get",
					contentType:'application/json',
					async:false,
					data:{
						'pageNo':pageNo,
						'pageSize':pageSize,
						'condition':condition,
						'startTime':startTime,
						'endTime':endTime
						},
					datatype:'json',
					success:function(data){
						pageNum = data.pageNum;
						$.each(data.misPage,function(){
							var tr = document.createElement("tr");
							tr.innerHTML="<td>"+this.id+"</td>"+
								         "<td>"+this.areaName+"</td>"+
										 "<td>"+this.manName+"</td>"+
										 "<td>"+new Date(this.misTime).toLocaleString()+"</td>"+
										 "<td>"+this.isFinish+"</td>"+
										 "<td>"+this.other+"</td>"+
										 "<td><a href='/pmsystem/security/updatemis?id="+this.id+"'>修改</a>/"+
				     					 "<a href='javascript:;' id='d"+this.id+"'>删除</a></td>"
							$("#mis table").append(tr);
							var id = this.id;
				     		var deleteId = "#d"+id;
				     		$(deleteId).click(function(){
								$.ajax({
									url:'deletemis',
									method:'get',
									contentType:'application/json',
									dataType:'json',
									data:{'id':id},
									success:function(data){
										showMis(pageNo,condition,startTime,endTime);
									}
								});
							});
						});
						for(var i=1;i<=pageNum;i++){
							if(i==pageNo){
								var a = "<a href='#' class='"+i+"' style='font-size:20px'>"+i+"<a/>";
								$("#misp").append(a);
							}else{
								var a = "<a href='#' class='"+i+"'>"+i+"<a/>";
								$("#misp").append(a);
							}
						}
						for(var i=1;i<=pageNum;i++){
							var id = "#misp ."+i;
							$(id).click(function(){
								showMis($(this).attr("class"),misCondition,misStartTime,misEndTime);
							});
						}
						if(data.misPage.length==0 && pageNum!=0)
							showMis(pageNo-1,condition,startTime,endTime);
					}
				})
			}
			function showProgress(){
				var date = new Date();
				var year = date.getFullYear();
				var month=date.getMonth();
				var day=date.getDate();
				if(month<9)
					month="0"+(month+1);
				if(day<10)
					day="0"+day;	
				date = year+"-"+month+"-"+day;
				$.ajax({
					url:'getprogress',
					method:'get',
					contentType:'application/json',
					dataType:'json',
					data:{'currentDate':date},
					success:function(data){
						$("#progress").html("当天任务进度:"+data+"%");
					}
				})
			}
			//重大事件信息
			var accCondition = $("#accCondition").val();
			var accTime = $("#accTime").val();
			$("#accSearch").click(function(){
				accCondition = $("#accCondition").val();
				accTime = $("#accTime").val();
				showAcc(1,accCondition,accTime);
			})
			showAcc(1,accCondition,accTime);
			function showAcc(pageNo,condition,time){
				var pageNum = 0 ;
				$("#acc table").html("<tr><th>事件ID</th><th>标题</th><th>内容</th><th>日期</th><th>处理过程</th><th>结果</th><th>负责人</th><th>联系方式</th><th>操作</th></tr>");
				$("#accp").html("");
				$.ajax({
					url:"findaccidentpage",
					type:"get",
					contentType:'application/json',
					async:false,
					data:{
						'pageNo':pageNo,
						'pageSize':pageSize,
						'condition':condition,
						'time':time
						},
					datatype:'json',
					success:function(data){
						pageNum = data.pageNum;
						$.each(data.accPage,function(){
							var tr = document.createElement("tr");
							tr.innerHTML="<td>"+this.accidentId+"</td>"+
					        			 "<td>"+this.accidentTitle+"</td>"+
										 "<td>"+this.accidentContent+"</td>"+
										 "<td>"+new Date(this.accidentTime).toLocaleString()+"</td>"+
										 "<td>"+this.processing+"</td>"+
										 "<td>"+this.result+"</td>"+
										 "<td>"+this.recorder+"</td>"+
										 "<td>"+this.recorderTelephone+"</td>"+
										 "<td><a href='/pmsystem/security/updateaccident?id="+this.accidentId+"'>修改</a>/"+
	     								 "<a href='javascript:;' id='d"+this.accidentId+"'>删除</a></td>"
							$("#acc table").append(tr);
							var id = this.accidentId;
				     		var deleteId = "#d"+id;
				     		$(deleteId).click(function(){
								$.ajax({
									url:'deleteaccident',
									method:'get',
									contentType:'application/json',
									dataType:'json',
									data:{'id':id},
									success:function(data){
										showAcc(pageNo,condition,time);
									}
								});
							});
						});
						for(var i=1;i<=pageNum;i++){
							if(i==pageNo){
								var a = "<a href='#' class='"+i+"' style='font-size:20px'>"+i+"<a/>";
								$("#accp").append(a);
							}else{
								var a = "<a href='#' class='"+i+"'>"+i+"<a/>";
								$("#accp").append(a);
							}
						}
						for(var i=1;i<=pageNum;i++){
							var id = "#accp ."+i;
							$(id).click(function(){
								showAcc($(this).attr("class"),accCondition,accTime);
							});
						}
						if(data.accPage.length==0 && pageNum!=0)
							showAcc(pageNo-1,condition,time);
					}
				})
			}
		})
	</script>
</html>